package com.dstz.demo.rest.controller;

import com.dstz.base.api.response.impl.ResultMsg;
import com.dstz.base.core.util.StringUtil;
import com.dstz.base.rest.BaseController;
import com.dstz.demo.core.manager.TProjectInfoManager;
import com.dstz.demo.core.model.TProjectInfo;
import com.dstz.sys.util.ContextUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/sys/TProjectInfo")
public class TProjectInfoController extends BaseController<TProjectInfo> {
    @Resource
    TProjectInfoManager tProjectInfoManager;
    @Override
    protected String getModelDesc() {
        return null;
    }
    @GetMapping("/findlist")
    public List<TProjectInfo> findlist(){
        List<TProjectInfo> list=tProjectInfoManager.findlist();
        return list;
    }
    @GetMapping("/test")
    public ResultMsg updateProjectInfo  (HttpServletRequest request, HttpServletResponse response){
        ResultMsg resultMsg = new ResultMsg();

/*      Map<String,Object> map = new HashMap<>();
      map.put("projectId",2020);
      map.put("projectName","测试项目名称");*/
        Cookie cookie = new Cookie("projectInfo", "2020");
        String userid= ContextUtil.getCurrentUserId();
        request.getSession().setAttribute(userid,"projectid");

        String contextPath = request.getContextPath();
        if(StringUtil.isEmpty(contextPath)) {
            contextPath = "/";
        }
        cookie.setPath(contextPath);
        response.addCookie(cookie);
        resultMsg.setOk(true);
        resultMsg.setMsg("切换项目成功");
        return  resultMsg;
    }
}
